<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-button v-if="$AUTH('seller:sellerWithdrawal:add')" type="primary" icon="el-icon-plus" @click="add"></el-button>
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <!-- 日期时间范围 -->
          <el-date-picker v-model="search.createTime" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"></el-date-picker>
          <el-input v-model="search.sellerWithdrawalId" placeholder="商家提现结算记录" clearable></el-input>
          <el-input v-model="search.sellerId" placeholder="商家" clearable></el-input>
          <el-input v-model="search.createTime" placeholder="申请时间" clearable></el-input>
          <el-input v-model="search.status" placeholder="状态 0失效 1有效" clearable></el-input>
          <el-input v-model="search.msg" placeholder="申请说明" clearable></el-input>
          <el-input v-model="search.collectionType" placeholder="取款账号类别 1微信 4支付宝 9网银 20线下" clearable></el-input>
          <el-input v-model="search.collectionName" placeholder="取款账号名称" clearable></el-input>
          <el-input v-model="search.collectionAccount" placeholder="取款账号NO" clearable></el-input>
          <el-input v-model="search.checkUserId" placeholder="审核人" clearable></el-input>
          <el-input v-model="search.checkTime" placeholder="审核时间" clearable></el-input>
          <el-input v-model="search.checkState" placeholder="审核状态 0待审核 1审核通过 5审核不通过" clearable></el-input>
          <el-input v-model="search.checkMsg" placeholder="审核说明" clearable></el-input>
          <el-input v-model="search.payUserId" placeholder="转账人" clearable></el-input>
          <el-input v-model="search.payTime" placeholder="转账时间" clearable></el-input>
          <el-input v-model="search.payState" placeholder="转账状态 0待转账 1已转账 5转账失败" clearable></el-input>
          <el-input v-model="search.payMsg" placeholder="转账说明" clearable></el-input>
          <el-input v-model="search.deleted" placeholder="" clearable></el-input>
          <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable ref="table" :apiObj="apiObj" row-key="sellerWithdrawalId" @selection-change="selectionChange" stripe>
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column label="商家提现结算记录" prop="sellerWithdrawalId" width="150"></el-table-column>
        <el-table-column label="商家" prop="sellerId" width="150"></el-table-column>
        <el-table-column label="申请时间" prop="createTime" width="150"></el-table-column>
        <el-table-column label="状态 0失效 1有效" prop="status" width="150"></el-table-column>
        <el-table-column label="申请说明" prop="msg" width="150"></el-table-column>
        <el-table-column label="取款账号类别 1微信 4支付宝 9网银 20线下" prop="collectionType" width="150"></el-table-column>
        <el-table-column label="取款账号名称" prop="collectionName" width="150"></el-table-column>
        <el-table-column label="取款账号NO" prop="collectionAccount" width="150"></el-table-column>
        <el-table-column label="审核人" prop="checkUserId" width="150"></el-table-column>
        <el-table-column label="审核时间" prop="checkTime" width="150"></el-table-column>
        <el-table-column label="审核状态 0待审核 1审核通过 5审核不通过" prop="checkState" width="150"></el-table-column>
        <el-table-column label="审核说明" prop="checkMsg" width="150"></el-table-column>
        <el-table-column label="转账人" prop="payUserId" width="150"></el-table-column>
        <el-table-column label="转账时间" prop="payTime" width="150"></el-table-column>
        <el-table-column label="转账状态 0待转账 1已转账 5转账失败" prop="payState" width="150"></el-table-column>
        <el-table-column label="转账说明" prop="payMsg" width="150"></el-table-column>
        <el-table-column label="" prop="deleted" width="150"></el-table-column>
<!--    <el-table-column label="创建时间" prop="createTime" width="150" :formatter="formatDate"></el-table-column>-->
        <el-table-column label="操作" fixed="right" align="right">
          <template #default="scope">
            <el-button v-if="$AUTH('seller:sellerWithdrawal:edit')" type="text" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
            <el-divider direction="vertical"></el-divider>
            <el-button v-if="$AUTH('seller:sellerWithdrawal:del')" type="text" size="small" @click="table_del(scope.row, scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>

  <sellerWithdrawalEdit-dialog v-if="dialog.sellerWithdrawalEdit" ref="sellerWithdrawalEditDialog" @success="handleSaveSuccess" @closed="dialog.sellerWithdrawalEdit=false"></sellerWithdrawalEdit-dialog>
</template>

<script>
  import sellerAPI from '@/api/seller/sellerWithdrawal';
  import sellerWithdrawalEditDialog from './sellerWithdrawalEdit';//1--导入
  export default {
    name: 'sellerWithdrawal',
    components: {
        sellerWithdrawalEditDialog//2发布
    },
    data() {
      return {
        dialog: {
          sellerWithdrawalEdit: false
        },
        apiObj: sellerAPI.sellerWithdrawal.list,
        selection: [],
        search: {
          keyword: null,
          createTime: null
        }
      }
    },
    methods: {
      //添加
      add(){
        this.dialog.sellerWithdrawalEdit = true
        this.$nextTick(() => {
          this.$refs.sellerWithdrawalEditDialog.open()
        })
      },
      //编辑
      table_edit(row){
        this.dialog.sellerWithdrawalEdit = true
        this.$nextTick(() => {
          this.$refs.sellerWithdrawalEditDialog.open('edit').setData(row)
        })
      },
      //删除
      async table_del(row){
        var confirm = await this.$confirm('确定删除选中的项吗？', '提示', {
          confirmButtonText: 'ok',
          type: 'warning'
        }).catch(() => {})
        if(confirm !== 'confirm'){
          return false;
        }
        var res = await sellerAPI.sellerWithdrawal.delete.delete(row.sellerWithdrawalId);
        if(res.code === 2000){
          this.$refs.table.refresh();
          this.$message.success("删除成功");
        }else{
          this.$alert(res.message, "提示", {type: 'error'});
        }
      },
      //表格选择后回调事件
      selectionChange(selection){
        this.selection = selection;
      },
      //搜索
      upsearch(){
        this.$refs.table.upData(this.search);
      },
      //本地更新数据
      handleSaveSuccess(){
        this.$refs.table.refresh();
      },
      handlePermissionSuccess(){
        this.$refs.table.refresh();
      },
      handleDataSuccess(){
        this.$refs.table.refresh();
      },
      formatDate(row,column) {// 获取单元格数据
        let data = row[column.property];
        if(data == null) {
          return null;
        }
        let dt = new Date(data);
        return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds();
      },
    }
  }
</script>
<style>
</style>
